<?php

namespace Core\annotationshandlers;

use Core\annotations\Bean;
use Core\annotations\Value;

return [
    //类注解
    Bean::class => function ($instance, $container, $self) {
        //对自定义注解进行适配
        $var = get_object_vars($self);
        if (isset($var['name']) && $var['name'] !== '') {
            $beanName = $var['name'];
        } else {
            $arrs = explode("\\", get_class($instance));
            $beanName = end($arrs);
        }

        $container->set($beanName, $instance);
    },

    //属性注解
    Value::class => function (\ReflectionProperty $prop, $instance, $self) {
        $env = parse_ini_file(ROOT_PAHT . "/env");
        if (!isset($env[$self->name]) || $self->name == "") return $instance;
        $prop->setValue($instance, $env[$self->name]);
        return $instance;
    }

];
